package factory.filter;


import java.util.ArrayList;
import java.util.List;

public class CriteriaPatternDemo {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<Person>();

        persons.add(new Person("Robert1", "男", "是"));
        persons.add(new Person("Robert2", "男", "否"));
        persons.add(new Person("Robert3", "女", "否"));
        persons.add(new Person("Robert4", "女", "是"));
        persons.add(new Person("Robert5", "男", "是"));
        persons.add(new Person("Robert6", "男", "是"));

        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleFemale = new AndCriteria(single, female);
        Criteria singleOrFemale = new OrCriteria(single, female);

        System.out.println("所有男生: ");
        printPersons(male.meetCriteria(persons));

        System.out.println("\n所有女生: ");
        printPersons(female.meetCriteria(persons));
//
        System.out.println("\n男单身狗: ");
        printPersons(singleMale.meetCriteria(persons));
//
        System.out.println("\n女单身狗: ");
        printPersons(singleFemale.meetCriteria(persons));

        System.out.println("\n单身或者是女生: ");
        printPersons(singleOrFemale.meetCriteria(persons));
    }

    public static void printPersons(List<Person> persons) {
        for (Person person : persons) {
            System.out.println("Person : [ 姓名 : " + person.getName()
                    + ", 性别 : " + person.getGender()
                    + ", 单身狗 : " + person.getMaritalStatus()
                    + " ]");
        }
    }
}
